import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase="DBshop003_货到付款流程"
firefox=openBrowser(url)
DBshopLogin(firefox,userName,password)
#在首页的搜索框输入小米
firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')
#点击搜索按钮
firefox.find_element_by_xpath('//input[@type="submit"]').click()

firefox.find_element_by_xpath("//a[@href='/dbshop/goods/8/2']").click()
switchWindow(firefox,2)
firefox.find_element_by_id('add_cart_submit').click()
time.sleep(2)
#点击去购物车结算按钮
firefox.find_element_by_link_text('去购物车结算').click()
# 3.点击"去结算"按钮
firefox.find_element_by_link_text('去结算').click()

firefox.find_element_by_xpath("//input[@value='下一步']").click()
firefox.find_element_by_xpath("//input[@value='hdfk']").click()
firefox.find_element_by_xpath("//input[@value='确认订单']").click()
orderId=firefox.find_element_by_xpath("(//font[@color='color:#ED145B'])[2]").text
rootPath=get_pro_rootpath()
# 将订单编号写入到文件中,方面后面的脚本去使用这个订单编号
#这就是跨脚本传递数据
writeFile(rootPath+'\public\order003.txt',orderId)
firefox.quit()

firefox=firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"销售管理","订单管理")
firefox.find_element_by_name('order_sn').send_keys(orderId)
firefox.find_element_by_xpath('//button').click()#点击搜索按钮
firefox.find_element_by_link_text('编辑查看').click()
firefox.find_element_by_link_text('发货操作').click()
firefox.find_element_by_id("express_number").send_keys("1000000000")
firefox.find_element_by_id("state_info").send_keys("保证正品")

firefox.find_element_by_xpath('//button').click()
firefox.find_element_by_link_text("付款操作").click()
firefox.find_element_by_xpath("//select[@name='pay_state']/option[3]").click()
firefox.find_element_by_id("state_info").send_keys('已收到付款')
firefox.find_element_by_xpath("//button").click()

firefox.get(url)
DBshopLogin(firefox,userName,password)
#点击我的订单
firefox.find_element_by_link_text('我的订单').click()
#点击已发货
firefox.find_element_by_partial_link_text('已发货').click()#点击已发货页签
firefox.find_element_by_name('search_order_sn').send_keys(orderId)#输入订单编号
firefox.find_element_by_xpath('//button').click() #点击搜索按钮
#点击确认收货
firefox.find_element_by_xpath('//button[text()="确认收货"]').click()#点击确认收货按钮
firefox.find_element_by_xpath('//button[@type="submit"]').click()
firefox.switch_to.alert.accept() #处理js弹框，点击确定按钮
# 12.到dbshop前台查看我的订单"交易完成"中,检查上面的订单状态
#点击交易完成
firefox.find_element_by_partial_link_text('交易完成').click()#点击交易完成页签
firefox.find_element_by_name('search_order_sn').send_keys(orderId) #输入订单编号
firefox.find_element_by_xpath('//button').click() #点击搜索按钮
#断言
try:
    firefox.find_element_by_link_text(orderId)
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
